package com.zengqingfa.algorithm.cz.chapter02;

import java.util.Arrays;

/**
 * @author zengqingfa
 * @className BubbleSort2
 * @description
 * @create 2021/8/6 11:38
 */
public class BubbleSort2 {

    public static void main(String[] args) {
        int[] a = {3, 4, 5, 9, 1, 2};
        sort(a);
        System.out.println(Arrays.toString(a));
    }


    public static void sort(int[] arr) {
        int temp;
        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < arr.length - i - 1; j++) {
                if (arr[j] > arr[j + 1]) {
                    temp = arr[j];
                    arr[j] = arr[j + 1];
                    arr[j + 1] = temp;
                }
            }
        }
    }
}